<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>填写预计上门时间</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/global.css">
		<link rel="stylesheet" href="../../css/style.css">
		<style>
			.selectDate{
				color: #333;
			}
			.inline-block{
				color: #999999;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">填写预计上门时间</h1>
		</header>
		<div class="mui-content">
			<div class="details_con">
				<div class="clum">
					<span class="name">服务编号</span>
					<span class="txt">170001</span>
				</div>
				<div class="clum">
					<span class="name">服务角色</span>
					<span>
						<input class="serviceRole" name="serviceRole" type="radio" value="1" disabled="disabled">现场服务
						<input class="serviceRole" name="serviceRole" type="radio" value="2" disabled="disabled">实习
					</span>

				</div>
				<div class="my-content-cell">
					<div class="inline-block" id="pjcgqd">
						<em>查看计划安排</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="clum">
					<span class="name">预计上门时间<em class="t_red">*</em></span>
					<button id='estimatedVisitingTime' type="button" class="selectDate">请选择时间</button>
				</div>
				<div class="clum">
					<span class="name">预计工时<em class="t_red">*</em></span>
					<input id="estimatedWorkingHours" type="number" class="d_ipt" placeholder="请输入预计工时" onchange="jisuan('1')"/>
				</div>
				<div class="clum">
					<span class="name">预计离开时间<em class="t_red">*</em></span>
					<span class="txt" id="estimatedDepartureTime">自动计算</span>
					<!-- <input id="estimatedDepartureTime" type="text" class="d_ipt" placeholder="自动计算" disabled="disabled"/> -->
				</div>
			</div>
			<div class="btn_box">
				<span class="fl">取消</span>
				<span class="fr red" id="save">保存</span>
			</div>
			<div style="height: 50px;"></div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/utils/h.js"></script>
		<script src="../../js/constant.js"></script>
		<script src="../../js/common.js"></script>
		<script src="../../js/utils/base64.js"></script>
		<script src="../../js/utils/md5.js"></script>
		<script src="../../js/utils/sortMap.js"></script>
		<script src="../../js/utils/http.js"></script>
		<script src="../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../js/utils/rolldate.min.js"></script>
		
		<script type="text/javascript" charset="utf-8">
			 //mui初始化
			(function($, doc) {
				$.init();
				
				new Rolldate({
					el: '#estimatedVisitingTime',
					format: 'YYYY-MM-DD hh:mm',
					beginYear: 2015,
					endYear: 2050,
					trigger: 'click',
					lang: {
						title: '请选择预计上门时间',
					},
					confirm: function(date) {
						jisuan(date)
					}
				})
				
				var ServiceNoticeId
				var serviceNo
				var planId
				var serviceRole
				var estimatedVisitingTime
				var estimatedWorkingHours
				var estimatedDepartureTime
				
			
				$.plusReady(function() {
					
					// 从上一个页面取值
					var self = plus.webview.currentWebview();
					 // 获取上一个页面传过来的参数并显示到页面
					 ServiceNoticeId = self.ServiceNoticeId;
					 serviceNo = self.serviceNo;
					 planId = self.planId;
					 serviceRole = self.serviceRole;
					 console.log(self.serviceRole) 
					 if (serviceRole) {
						 // h(".serviceRole").find("input[name='serviceRole'][value='1']").attr('checked','true');
						 document.querySelector(`input[name='serviceRole'][value='${serviceRole}']`).checked=true;
					 }
					 
					 
					
					// 保存
					h("#save").tap(function() {
						estimatedVisitingTime = h("#estimatedVisitingTime").html();
						if(estimatedVisitingTime==null || estimatedVisitingTime=="" || estimatedVisitingTime=="请选择时间"){
							app.toast("请选择预计上门时间");
							return
						}
						estimatedWorkingHours = h("#estimatedWorkingHours").val();
						if(estimatedWorkingHours==null || estimatedWorkingHours==""){
							app.toast("请选择预计工时");
							return
						}
						estimatedDepartureTime = h("#estimatedDepartureTime").html();
		
						ajaxGet(BASE_URL + "cc/notice/AssociatedCustomers", {
							"ServiceNoticeId": ServiceNoticeId,
							"EnginnerId": "10009",
							"state": "0"
						}, function(data) {
							if(data.code==200){
								if(data.data && data.data.length > 1){
									// 跳转页面
									jumpToRelationNotices();								
								}else{
									saveIn();
								}
							}
						}, function(errorMsg) {
							console.log(JSON.stringify(errorMsg))
						});
						
					});
					
					// 查看计划安排
					h("#pjcgqd").tap(function() {
						app.toast("暂未开放")
					});
					
					// 跳转页面方法
					var jumpToRelationNotices = function(){
						// 跳转页面
						app.jumpTo("relationNotices.html",
						  "view/service/relationNotices.html",
						  {
						   ServiceNoticeId: ServiceNoticeId,
						   serviceNo: serviceNo,
						   planId: planId,
						   serviceRole: serviceRole,
						   estimatedVisitingTime: estimatedVisitingTime,
						   estimatedWorkingHours: estimatedWorkingHours,
						   estimatedDepartureTime: estimatedDepartureTime
						  })
					}
					
					var saveIn = function(){
						app.toast("进入方法")
						ajaxGet(BASE_URL + "cc/PlanDetails/fseAccept", {
							"ServiceNoticeIds": ServiceNoticeId,
							"serviceNos": serviceNo,
							"planIds": planId,
							"EnginnerId": "10009",
							"serviceRole": serviceRole,
							"StartTime": estimatedVisitingTime,
							"workingHours": estimatedWorkingHours,
							"EndTime": estimatedDepartureTime
						}, function(data) {
							console.log(JSON.stringify(data))
							if(data.code==200){
								app.toast("保存成功")
							}
						}, function(errorMsg) {
							console.log(JSON.stringify(errorMsg))
						});
					}
					
				});
				
				
				
			}(mui, document));
			
			// 自动计算方法
			function jisuan(date){
				var estimatedVisitingTime;
				if(date!="1"){
					estimatedVisitingTime = date
				}else{
					estimatedVisitingTime = h("#estimatedVisitingTime").html();
				}
				if(estimatedVisitingTime==null || estimatedVisitingTime=="" || estimatedVisitingTime=="请选择时间"){
					return
				}
				var evt = new Date(estimatedVisitingTime).getTime();
				var estimatedWorkingHours = h("#estimatedWorkingHours").val();
				if(estimatedWorkingHours==null || estimatedWorkingHours==""){
					return
				}
				var edt = evt + estimatedWorkingHours * 60 *60 * 1000;
				var estimatedDepartureTime = new Date(edt).Format("yyyy-MM-dd HH:mm");
				h("#estimatedDepartureTime").html(estimatedDepartureTime);
			}
			
		</script>
		<!-- js代码 end -->

	</body>

</html>
